// index.js
const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'
Page({
  onInput(event){
    this.setData({
      inputValue:event.detail.value
    });
  },
  data: {
    inputValue:'',
    outLength:'',
    image:'received_image_20241006_084747.jpg',
    mysqlData:[]
    },
  onLoad(option){
    wx.request({
      url: 'https://kaopu328.site:3000/',
      success:(res)=>{
        this.setData({
          mysqlData:res.data
        });
      },
      fail:function(){
        console.log("shibai");
      }
    });
    
  },
  getdata(){
    wx.request({
      url: 'https://kaopu328.site:3000/shuju',
      success:res=>{
        const dbData=res.data;
        this.setData({dbData});
        this.compareData(dbData);
      },
      fail:err=>{
        console.error('shibai',err);
      }
    });
  },
  getmachine(){
    wx.request({
      url: 'https://kaopu328.site:3000/shuju',
      success:res=>{
        const dbData=res.data;
        const machine = Array.from(new Set(dbData));
        console.log(machine);
        wx.showModal({
          title: '机器码如下',
          content: `${machine}`
        });
      }
    });
  },
  compareData(dbData){
    const item = this.data.inputValue;
    const isMatch = dbData.includes(item);
    if(isMatch){
      wx.navigateTo({
        url: `/pages/jm1/jm1?inputValue=${encodeURIComponent(this.data.inputValue)}`,
      });
    }else{
      wx.showModal({
        title: 'error',
        content: 'input cuowu'
      });
    }
  },
  })
